#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <functional>

using namespace std;
int main() {
	string str{ "9+(3-1)*3+10/2" };
	vector<int> arr;
	stack<char> stack;
	auto hash = [](char c) -> int {
		int res = 0;
		switch (c) {
			case '+':res = 1; break;
			case '-':res = 1; break;
			case '*':res = 2; break;
			case '/':res = 2; break;
		}
		return res;
	};
	string tmp = "";
	function<void()> culculate = [&] () {
		auto&& sign = stack.top();
		stack.pop();
		int& a = arr[arr.size() - 2], & b = arr[arr.size() - 1];
		int result = 0;
		switch (sign) {
			case '+':result = a + b; break;
			case '-':result = a - b; break;
			case '*':result = a * b; break;
			case '/':result = a / b; break;
		}
		arr.pop_back(); arr.pop_back();
		arr.push_back(result);
	};

	for (auto& c : str) {
		if ('0' <= c && c <= '9') {
			tmp += c;
			continue;
		}
		if (!tmp.empty()) {
			arr.push_back(stoi(tmp));
			tmp.clear();
		}
		if (stack.empty()) stack.push(c);
		else if (c == '(' || hash(stack.top()) < hash(c)) stack.push(c);
		else if (c == ')') {
			while (stack.top() != '(') culculate();
			stack.pop();
		}
		else {
			while (!stack.empty() && hash(stack.top()) >= hash(c)) culculate();
			stack.push(c);
		}
	}
	while (!stack.empty()) {
		if (!tmp.empty()) {
			arr.push_back(stoi(tmp)); 
			tmp.clear();
		}
		culculate();
	}

	cout << arr[0];
}